
import 'package:flutter/material.dart';
import 'package:provide/provide.dart';
import '../../provide/details_info.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class DetailsTopArea extends StatelessWidget {
  const DetailsTopArea({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Provide<DetailsInfoProvide>(
      builder: ( context,child,detailsInfoProvide){
        var goodsInfo=Provide.value<DetailsInfoProvide>(context).goodsinfo.data.goodInfo;
        if(goodsInfo != null){
            return Container(
            decoration: BoxDecoration(
              color: Colors.white
            ),
            child: Column(
              children: <Widget>[
                _goodsImage(goodsInfo.image1),
                _goodsname(goodsInfo.goodsName),
                _goodsNum(goodsInfo.goodsSerialNumber),
                _goodsPrice(goodsInfo.oriPrice, goodsInfo.presentPrice)
              ],
            ),
          );
        }else{
          return Center(
            child: Text('加载中')
          );
        }
      }
    );
  }
  //商品图片
  Widget _goodsImage(url){
    return Image.network(
      url,
      width: ScreenUtil().setWidth(740),
      height:ScreenUtil().setHeight(750.0),
    );
  }

  //商品名称
  Widget _goodsname(name){
    return Container(
      width: ScreenUtil().setWidth(740),
      padding: EdgeInsets.only(left: 15.0),
      child: Text(
        '$name',
         maxLines: 1,
         overflow: TextOverflow.ellipsis,
          style: TextStyle(
            fontSize: ScreenUtil().setSp(30),
          ),
      ),
    );
  }

  //商品编号
  Widget _goodsNum(num){
    return Container(
      width: ScreenUtil().setWidth(740),
      padding: EdgeInsets.only(left: 15.0),
      margin: EdgeInsets.only(top:8.0),
      child: Text(
        '编号:$num',
        style: TextStyle(
          color: Colors.black12
        ),
      ),
    );
  }

  //价格(市场价，价格)
  Widget _goodsPrice(oriPrice,presentPrice){
    return Container(
      width: ScreenUtil().setWidth(740),
      padding: EdgeInsets.only(left: 15.0),
      margin: EdgeInsets.only(top:8.0,bottom: 20.0),
      child: Row(
        children: <Widget>[
          Text('￥$presentPrice',style: TextStyle(
            color: Colors.orangeAccent
          ),),
          SizedBox(
            width: ScreenUtil().setWidth(45.0),
          ),
          Text(
          '市场价:$oriPrice',
          style: TextStyle(
            color: Colors.black12,
            decoration: TextDecoration.lineThrough
          ),),
        ],
      ),
    );
  }

}
